import { Input } from 'antd';
import React from 'react';
import styles from './index.less';
type ValueType = {
  // 额度
  quota?: number | string;

  // 数量限制
  limit?: number | string;
};

interface Props {
  value?: ValueType[];
  disabled?: boolean;
  onChange?: (value?: ValueType[]) => void;
}

const Index: React.FC<Props> = ({ value = [], onChange, disabled }) => {
  const handleChange = (key, _value) => {
    const newValue = [...value];
    const item = newValue[0] || {};
    item[key] = _value?.replace(/^(0+)|[^\d]+/g, '');
    newValue[0] = item;
    onChange?.(newValue);
  };
  return (
    <div className={styles.container}>
      <Input
        disabled={disabled}
        placeholder="CG券额度"
        className={styles.input}
        value={value?.[0]?.quota}
        onChange={(e) => handleChange('quota', e.target.value)}
        type="number"
      />
      <Input
        disabled={disabled}
        placeholder="填写赠送数量"
        className={styles.input}
        value={value?.[0]?.limit}
        onChange={(e) => handleChange('limit', e.target.value)}
        type="number"
      />
    </div>
  );
};

export default Index;
